import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../helper/channelHelper.dart';

import '../../helper/routeHelper.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/inputWidget.dart';
import '../../model/shipuse.dart';
import '../../helper/uidata.dart';
import 'shipuse_authorty.dart';

class ShipUseHuiZhiPage extends StatefulWidget {
  @override
  ShipUseHuiZhiPage(this.s1, this.added);
  final ShipUse s1;
  final VoidCallback added;
  @override
  ShipUseHuiZhiPageState createState() => new ShipUseHuiZhiPageState();
}

class ShipUseHuiZhiPageState extends State<ShipUseHuiZhiPage> {
  late ShipUse X1;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    X1 = widget.s1;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      floatingActionButton: getFloatingButton(context),
      body: ShipUseHuiZhiBody(context),
    );
  }

  Widget getFloatingButton(BuildContext context) {
    if (X1 == null) return new Container();
    if (X1.State < 4) return new Container();

    if (ShipUseAuthority.IfHuiZhi(UIData.CurrentUser!)) {
      return FloatingActionButton(
          child: Icon(FontAwesomeIcons.penAlt),
          onPressed: () {
            RouteHelper.ShipUseHuiZhiAdd(context, X1, () => {});
          });
    }

    return new Container();
  }

  List<Widget> getWidgetList(BuildContext context) {
    List<Widget> list1 = <Widget>[];
    List<Widget> list2 = <Widget>[];
    List<Widget> list3 = <Widget>[];

    list1.add(InputWidget.inCard(ShipUseAuthority.GetShipTitle(X1)));

//print(X1.ManaName);
    //list2.add(InputWidget.getInfo("船艇管理人员", X1.ManaName));

    list2.add(InputWidget.getInfo("航行船只", X1.ChuanBo2));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo2("航行时段", X1.UseTime2));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo("乘船人次", X1.Peoples.toString()));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo("航行公里", X1.Length.toString()));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo("船艇管理人员", X1.ManaName2));
    list2.add(Divider(
      height: 0.0,
    ));

    list1.add(InputWidget.inCard2(list2));

    list3.add(InputWidget.getInfo2("船长及船员", X1.CZName2));
    list3.add(Divider(
      height: 0.0,
    ));
    list3.add(InputWidget.getInfo2("航行路线", X1.UsePath2));
    list3.add(Divider(
      height: 0.0,
    ));
    list3.add(InputWidget.getInfo2("天气及库面情况", X1.TianQi));
    list3.add(Divider(
      height: 0.0,
    ));
    list3.add(InputWidget.getInfo2("航行情况", X1.HangXing));
    list3.add(Divider(
      height: 0.0,
    ));
    list3.add(InputWidget.getInfo("填报人", X1.CunDang));

    list1.add(InputWidget.inCard2(list3));

    if (X1.State >= 5) {
      // list1.add(InputWidget.inCard(InputWidget.getButton("下载报表", () async {
      //   await DownloadHelper.DownLoadBaoBiao(
      //       context,
      //       "http://47.95.205.213:22351/download?id=" + X1.ID.toString(),
      //       "用船申请" + X1.Title + "_");
      //   await ChannelHelper.showToast("已下载，请到下载列表里查看");
      // })));
    }

    //list1.add(getCLWidget(s1.State==6, Helper.DateTimeFormat(s1.HZQMTM), s1.HZQM));
    return list1;
  }

  ShipUseHuiZhiBody(BuildContext context) => SingleChildScrollView(
        child: ShipUseHuiZhiFields(context),
      );

  ShipUseHuiZhiFields(BuildContext context) {
    print(X1.State);
    if (X1.State < 6)
      return Container(
        child: Center(child: Text("未执行")),
      );

    return Container(child: Column(children: getWidgetList(context)));
  }
}
